<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-20 13:42:52
 * @Last Modified by:   Wang chunsheng  email:2192138785@qq.com
 * @Last Modified time: 2020-05-16 13:35:58
 */


namespace common\addons\diandi_shop\models;

use Yii;

/**
 * This is the model class for table "dd_diandi_shop_cart".
 *
 * @property int $id
 * @property int|null $user_id 用户id
 * @property int|null $goods_id 商品id
 * @property int|null $spec_id 规格组合id
 * @property int|null $number 数量
 * @property int|null $create_time 创建时间
 */
class DdDiandiShopCart extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'dd_diandi_shop_cart';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id','bloc_id','store_id', 'goods_id', 'number', 'create_time'], 'integer'],
            [['spec_id', 'spec_val'], 'string'],
            [['total_price','goods_price','line_price'], 'number'],
        ];
    }

       /**
     * 行为.
     */
    public function behaviors()
    {
        /*自动添加创建和修改时间*/
        return [
            [
                'class' => \common\behaviors\SaveBehavior::className(),
            ],
        ];
    }

    /* 获取分类 */
    public function getGoods()
    {
        return $this->hasOne(DdGoods::className(), ['goods_id' => 'goods_id']);
    }

    /* 获取分类 */
    public function getGoodsSpec()
    {
        return $this->hasOne(DdGoodsSpec::className(), ['spec_sku_id' => 'spec_id']);
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户id',
            'goods_id' => '商品id',
            'spec_id' => '规格组合id',
            'spec_val' => '规格组合',
            'number' => '数量',
            'create_time' => '创建时间',
        ];
    }
}
